package com.hyts.monitor.profile.config;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

import java.io.File;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * project-name:coffice-toolbox
 * package-name:com.hyts.monitor.profile.config
 * author:Libo/Alex
 * create-date:2019-07-04 15:06
 * email:liboware@gmail.com
 * description:此类主要用于:
 */
public interface ProfilerConfig {


    /**
     * file文件的相关配置
     */
    interface FileConfig {

        String DEFAULT_LOG_PATH = File.separator+"log"+File.separator+"logs"+File.separator;

        String DEFAULT_CONFIG_NAME = "profiler.properties";

        String DEFAULT_CONFIG_PATH = File.separator+"config"+File.separator+DEFAULT_CONFIG_NAME;

        String DEFAULT_CONFIG_PATH_01 = System.getProperty("user.home")+ DEFAULT_CONFIG_PATH;

        String DEFAULT_CONFIG_PATH_02 = System.getProperty("user.dir")+ DEFAULT_CONFIG_PATH;

        String DEFAULT_LOGIN_FULL_PATH = System.getProperty("user.dir")+ DEFAULT_LOG_PATH;

        /**
         * 基础配置默认key的prefix前缀标识符
         */
        String CONFIG_KEY_PREFIX = "profiler.";
    }

    /**
     * attribute属性配置服务接口
     */
    interface AttributeConfig{

        boolean USE_NANO_LEVEL = false;

        boolean INGNORE_GETTER_SETTER = false;

        boolean DEFAULT_DEBUG_MODEL = false;

        boolean DEFAULT_OPEN_ACCESS_REMOTE = true;

        int DEFAULT_DATA_QUEUE_SIZE = 65535;

        int DEFAULT_METHOD_CACHE_SIZE = 10240;

        boolean DEFAULT_TIME_FIX_MODEL = false;

        String DEFAULT_PROFILER_TIME_FORMAT = "HH:mm:ss";

        String DEFAULT_PROFILER_LOG_NAME_PREFIX = "profiler-log-";

    }

    /**
     * 连接操作
     */
    interface ConnectorConfig{

        String DEFAULT_IP = "127.0.0.1";

        Integer DEFAULT_PORT = 9802;

        String DEFAULT_USERNAME = "profiler";

        String DEFAULT_PASSWORD = "profiler";
    }

    /**
     * 命令操作
     */
    @AllArgsConstructor
    enum CommandConfig{

        /**
         * start 启动命令功能服务
         */
        LOGIN("login"),

        /**
         * stop 关闭命令功能服务
         */
        LOGOUT("logout"),

        /**
         * status 状态操作命令服务
         */
        STATUS("status"),

        /**
         * flush 操作刷新操作命令服务
         */
        FLUSH("flush"),

        /**
         * 无效操作
         */
        NOVAL("NONE");

        @Setter
        @Getter
        private String code;

        /**
         * 操作命令服务
         * @param str
         * @return
         */
        public static CommandConfig getObject(String str){
            Objects.requireNonNull(str);
            List<CommandConfig> list = Stream.of(ProfilerConfig.CommandConfig.values()).
                    filter(str::equals).collect(Collectors.toList());
            if(list == null || list.size() == 0){
                return CommandConfig.NOVAL;
            }
            return list.get(0);
        }
    }

    /**
     * 操作相关的filter过滤器操作配置
     */
    interface FilterConfig{

        Set<String> DEFAULT_NOT_PROFILER_PACKAGE = new HashSet<String>(){{
            add("java");add("sun");add("com.sun");add("org");add("com.hyts.monitor");
        }};

    }

}
